/*
 * Copyright 2016-2021 the original author.All rights reserved.
 * Kingstar(honeysoft@126.com)
 * The license,see the LICENSE file.
 */

package com.aiteasoft.school.scores.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.teasoft.bee.osql.Condition;
import org.teasoft.bee.osql.Op;
import org.teasoft.bee.osql.OrderType;
import org.teasoft.bee.osql.SuidRich;
import org.teasoft.honey.osql.core.BeeFactory;
import org.teasoft.honey.osql.core.BeeFactoryHelper;

import com.aiteasoft.school.scores.entity.Scores;
import com.aiteasoft.school.scores.service.ScoresService;
import com.automvc.common.jq.PageWarp;
import com.automvc.common.jq.Result;

/**
 * @author AiTeaSoft.com
 * @since  1.9
 * Create on 2021-01-18 18:29:19
 */
@Service
public class ScoresServiceImpl implements ScoresService {

	@Autowired
	SuidRich suidRich;

	@Override
	public Scores process(Scores entity) { 
		//Add the business logic if need. 放一些公共设置
		//判断用户角色. TODO
		entity.setStuno("20100003");  //TODO 从登录信息获取
//		entity.setStatus("FIN");
		return entity;
	}
	
	@Override
	public boolean isWrongBizForUpdate(Result result, Scores entity) {
		//Add the business logic if need.

		return false;
	}

	public PageWarp countAndSelect(Scores entity, int start, int size) {
	    Condition condition = getCondition(entity);
	    
		int total = suidRich.count(entity, condition);
		
		condition.start(start);
		condition.size(size);
		condition.orderBy("term", OrderType.DESC);
		List<Scores> listPage=suidRich.select(entity, condition);
		
		return new PageWarp(total,listPage);
	}
	
	private Condition getCondition(Scores entity) {
		Condition condition=BeeFactoryHelper.getCondition();
		//Add the business logic if need.
		condition.op("status", Op.nq, "INIT");
		return condition;
	}

}